package pers.mobian.myblog.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import pers.mobian.myblog.pojo.Tag;
import pers.mobian.myblog.pojo.Type;
import pers.mobian.myblog.service.BlogService;
import pers.mobian.myblog.service.TagService;
import pers.mobian.myblog.service.TypeService;
import pers.mobian.myblog.vo.BlogQuery;

import java.util.List;

@Controller
public class TagShowController {

    @Autowired
    private TagService tageService;

    @Autowired
    private BlogService blogService;

    @GetMapping("/tags/{id}")
    public String tags(@PageableDefault(size = 10, sort = {"updateTime"}, direction = Sort.Direction.DESC) Pageable pageable,
                        @PathVariable Long id, Model model) {
        //只要我的size值足够大，我们的标签就不会超范围
        List<Tag> tags = tageService.listTagTop(1000);

        if(id == -1) {
            id=tags.get(0).getId();
        }

        model.addAttribute("tags",tags);
        model.addAttribute("page",blogService.listBlog(id,pageable));
        model.addAttribute("activeTagId",id);
        return "tags";
    }
}
